package com.thread.demo11;

import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;

public class PipedDemo3 {
	public static void main(String[] args) throws IOException {
		PipedWriter out = new PipedWriter();
		PipedReader in = new PipedReader();
		out.connect(in);
		
		Thread printThread = new Thread(new Print(in),"print");
		printThread.start();
		int f = 0;
		while ((f= System.in.read())!=-1) {
			out.write(f);
		}
		
	}
	
	static class Print implements Runnable{
		private PipedReader in;
		
		public Print(PipedReader in) {
			this.in = in;
		}

		@Override
		public void run() {
			int f = 0;
			try {
				while ((f= in.read())!=-1) {
					System.out.print((char)f);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
